from .manage import Base
from src.core.variables.constant import *
from sqlalchemy import Column, String, Enum


class User(Base):
    """用户表"""

    __tablename__ = "user"
    __table_args__ = {"extend_existing": True}

    uid = Column(String, primary_key=True)
    username = Column(String, nullable=True)
    password = Column(String, nullable=True)
    # 邮箱
    email = Column(String, nullable=True)
    # 手机号
    phone = Column(String, nullable=True)
    # 角色
    roles = Column(String, nullable=True)
    # 创建时间
    create_time = Column(String, nullable=True)
    # 登录时间
    update_time = Column(String, nullable=True)
    # 最后登录时间
    last_login_time = Column(String, nullable=True)
    # 最后登录的ip
    last_login_ip = Column(String, nullable=True)
    # 登录次数
    login_count = Column(String, nullable=True)


class Role(Base):
    """角色表"""

    __tablename__ = "role"
    __table_args__ = {"extend_existing": True}

    uid = Column(String, primary_key=True)
    name = Column(String, nullable=True)
    # 说明
    description = Column(String, nullable=True)
    # 是否启用
    status = Column(String, nullable=True)
    # 创建用户
    create_user = Column(String, nullable=True)
    # 更新用户
    update_user = Column(String, nullable=True)
    # 创建时间
    create_time = Column(String, nullable=True)
    # 更新时间
    update_time = Column(String, nullable=True)


class Node(Base):
    __tablename__ = "node"
    __table_args__ = {"extend_existing": True}

    node_id = Column(String, primary_key=True)
    host = Column(String, nullable=False)
    ip = Column(String, nullable=False)
    port = Column(String, nullable=False)
    # fm状态
    status = Column(String, nullable=False)
    # 操作系统
    os_type = Column(String, nullable=False)
    # 操作系统版本
    os_version = Column(String, nullable=False)
    # 内核版本
    kernel_version = Column(String, nullable=False)
    # cpu核心数
    cpu_cores = Column(String, nullable=False)
    # cpu指令集
    cpu_instruction_set = Column(String, nullable=False)
    # cpu型号
    cpu_model = Column(String, nullable=False)
    # 内存大小
    mem_size = Column(String, nullable=False)
    # 磁盘信息
    disk_info = Column(String, nullable=False)
    # 证书
    certificate = Column(String, nullable=False)


# class Runner(Base):
#     """Runner表"""

#     __tablename__ = "runner"
#     __table_args__ = {"extend_existing": True}

#     uid = Column(String, primary_key=True)
#     name = Column(String, nullable=True)
#     # 运行器类型
#     stype = Column(Enum(*HOSTING.BASIC.STYPE_LIST), nullable=True)
#     # 状态
#     status = Column(String, nullable=True)
#     # 运行器路径
#     runner_path = Column(String, nullable=True)
#     # 版本
#     version = Column(String, nullable=True)
#     # 包管理器
#     pkg_manager = Column(String, nullable=True)
#     # 包路径
#     pkg_path = Column(String, nullable=True)
#     # 虚拟环境
#     venv = Column(String, nullable=True)


class Function(Base):
    """功能表"""
    __tablename__ = "function"
    __table_args__ = {"extend_existing": True}
    
    uid = Column(String, primary_key=True)
    name = Column(String, nullable=False)
    status = Column(String, nullable=False)
    # 是否提醒，状态错误触发的系统重建数据库的提醒，提醒重新手动开启此功能
    is_tip = Column(String, nullable=False)
